# 更新系统包
sudo apt update
sudo apt upgrade -y

# 安装MySQL 8
sudo apt install mysql-server -y

# 检查MySQL服务状态
sudo systemctl status mysql

# 如果服务未启动，启动MySQL服务
sudo systemctl start mysql

# 设置MySQL服务开机自启
sudo systemctl enable mysql

# 安全配置MySQL
sudo mysql_secure_installation

# 登录MySQL
mysql -u root -p 